<?php
/*
 * Copyright (c) 2009 by Vsevolod Velichko <torkvemada@nigma.ru>
 *
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

/*
 * Uncomment the lines, commented with `#` symbol to evaluate rendering performance
 * Lines, commented with `//` are showing other possible Dingo functions
 */
//AA1BB1CC1DD1EE1FF1GG1HH1II1JJ1KK1LL1MM1NN1OO1PP1QQ1RR1SS1TT1UU1VV1WW1XX1YY1ZZ1
error_reporting(E_ALL|E_NOTICE);
$strings = array(
	"ClC(Br)(IЫ)CC>>ClC(Br)(I)CC(=O)O", //Illegal one
	"C=C.!!R!!>>CC",
	"CCCO>!!Na2SiO3!!>!!KMnO4!!.!!Na2SiO3!!.!!NaCl!!.!!Al2O3!!.!!NaClBrF!!.!!Na2SiO3!!.CC.CCC=O",
	"CCCC=C.!!RCOO-OOCR!!>>CCCC(Br)CBr",
	"CCCO",
	"[Cl:1][C:2]([Br:3])([I:4])[CH2:5][CH3:6]>>[Cl:1][C:2]([Br:3])([I:4])[CH2:5][C:6](=[O:7])[OH:8]",
	"C1=CC(CCN)=CCC1>C=C>C12CCC(CC2)C=C1(CCN)",
	"C1=CC(C#CC(CC)CC(CC)(CC)C)CC1C(=O)COCC(=O)O",
	"CCN(CC)C(=O)[C@H]1CN([C@@H]2CC3=CNC4=CC=CC(=C34)C2=C1)C",
	"CCCCC.!!KMnO4!!>>CCCC",
	"CN(CC(=O)N1C(CSC(-1)C1CC2CC(-1)CC2)C(=O)N[C@H](C)CCO)CC |a:20|",
);

if (class_exists("Cano"))
{
	// Here should be some notices 
	foreach ($strings as &$str)
	{
		$canonical = Cano::getCanonicalSmiles($str, "-AROMATICITY -TETRAHEDRAL");
		//$inchi = Cano::getInChI($str, "-AROMATICITY -TETRAHEDRAL"); //Don't work now.
		$str = ($canonical ? $canonical : $str);
	}
	unset ($str);}

if (class_exists("Dingo"))
{
	$render = new Dingo();
        $render->setLogPath("image.log");
        $render->setOutputFormat("svg");
        $render->setLoadHighlighting(true);
        $render->setBaseColor(0.07843, 0.23529, 0.62745);
        $render->setBondLength(50);
        $render->setMarginFactor(0.5);
        $render->setLabelMode("normal");
        $render->setImplicitHydrogenMode("all");
        $render->setColoring(false);
        $render->setValencesVisible(false);
        $render->setAtomIdsVisible(false);
        $render->setBondIdsVisible(false);
        $render->setStereoOldStyle(false);
        $render->setAromatization("arom");
        $render->setHighlightThicknessEnabled(false);
        $render->setHighlightColor(false);
        $render->setOutputFile("image.svg");
	$render->loadReactionFromString($strings[1]);
	$render->render();
	#$startTime = microtime(true);
	#$iterations = 1000;
	#for ($i=0; $i<$iterations; $i++)
	#{
/*
	$render1 = new Dingo();
	$render1->setLogPath("file.log");
	$render1->setLoadHighlighting(true);
	$render1->loadReactionFromString($strings[0]); //here should be a warning!
	$render1->loadReactionFromString($strings[1]);
	$render1->setOutputFormat("svg");
	$render1->setBaseColor(0.07843, 0.23529, 0.62745);
	$render1->setOutputFile("image.svg");
	// $render1->setImageSize(300, 200);
	// $render1->setBondLength(100.5);
	// $render1->setMarginFactor(100);
	// $render1->setRelativeThickness(0.55);
	// $render1->setBackgroundColor(128, 128, 128);
	$render1->setImplicitHydrogenMode("terminal");
	$render1->setColoring(false);
	$render1->setValencesVisible(false);
//	$render1->setAtomIdsVisible(false);
//	$render1->setBondIdsVisible(true);
//	$render1->setStereoOldStyle(false);
	//$render1->setAromatization("arom");
//	$render1->setLabelMode("normal");
//	$render1->setHighlightThicknessEnabled(false);
//	$render1->setHighlightColor(true, 0, 1, 0);
	// $render1->setAAMColor(1, 1, 0);
	// $render1->loadMolFromFile("filename");
	// $render1->loadMolFromString($strings[2]);
	// $render1->loadReactionFromFile("filename");
	// $render1->loadReactionFromString($strings[3]);
	$render1->render();
	$renderX = new Dingo();
	$renderX->setLogPath("file.log");
//	$renderX->setLoadHighlighting(true);
//	$renderX->loadReactionFromString($strings[0]); //here should be a warning!
	$renderX->loadReactionFromString(mb_strtolower($strings[1]));
	$renderX->setOutputFormat("svg");
	//$renderX->setBaseColor(0.07843, 0.23529, 0.62745);
	$renderX->setOutputFile("image2.svg");
	$renderX->render();
	$renderY = new Dingo();
	$renderY->setLogPath("file.log");
//	$renderY->setLoadHighlighting(true);
//	$renderY->loadReactionFromString($strings[0]); //here should be a warning!
	$renderY->loadReactionFromString($strings[2]);
	$renderY->setOutputFormat("svg");
	//$renderY->setBaseColor(0.07843, 0.23529, 0.62745);
	$renderY->setOutputFile("image3.svg");
	$renderY->render();

/*	$render2 = new Dingo();
	$render2->setLogPath("file2.log");
	$render2->setOutputFormat("png");
	$render2->loadReactionFromString($strings[4]);
	$render2->render();
	//$str = $render2->getRenderedString();
	//file_put_contents("image3.png", $str);
	//$render2->reset();
	$render2->setOutputFormat("svg"); 
	$render2->setOutputFile("image2.svg");
	$render2->setColoring(true);
	//$render2->setAromatization("dearom");
	//$render2->loadMolFromString($strings[5]);
	$render2->loadMolFromString($strings[6]);
	$render2->loadMolFromString($strings[7]);
	$render2->render();*/
	#}*/
}
#$endTime = microtime(true) - $startTime;
#$averageTime = $endTime/($iterations*3);
#echo "$endTime sec total\n";
#echo "~$averageTime sec per image\n";
?>
